package com.ericsson.rm.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.ericsson.rm.dao.repository.SkillDetailDaoRepository;
import com.ericsson.rm.model.SkillDetail;
import com.ericsson.rm.service.SkillDetailService;
import com.ericsson.rm.vo.SkillDetailVO;

@Service
public class SkillDetailServiceImpl implements SkillDetailService {
	
	@Autowired
	private SkillDetailDaoRepository skillDetailDaoRepository;

	@Override
	public List<SkillDetailVO> getAllSkillDetails() {
		
		List<SkillDetailVO> skillDetailVOList = null;
		List<SkillDetail> skillDetails = skillDetailDaoRepository.findAll();
		
		if(!CollectionUtils.isEmpty(skillDetails)){
			skillDetailVOList = new ArrayList<SkillDetailVO>();
			
			Iterator<SkillDetail> itr = skillDetails.iterator();
			
			while(itr.hasNext()){
				SkillDetailVO skillDetailVO = new SkillDetailVO();
				BeanUtils.copyProperties(itr.next(), skillDetailVO);
				skillDetailVOList.add(skillDetailVO);
			}
		}
		
		return skillDetailVOList;
	}

	@Override
	public List<SkillDetailVO> findBySkillTypeAndSkillDescription(
			String skillType, String skillDescription) {
		
		List<SkillDetailVO> skillDetailVOList = null;
		List<SkillDetail> skillDetails = skillDetailDaoRepository.findBySkillTypeAndSkillDescription(skillType, skillDescription);
		
		if(!CollectionUtils.isEmpty(skillDetails)){
			skillDetailVOList = new ArrayList<SkillDetailVO>();
			
			Iterator<SkillDetail> itr = skillDetails.iterator();
			
			while(itr.hasNext()){
				SkillDetailVO skillDetailVO = new SkillDetailVO();
				BeanUtils.copyProperties(itr.next(), skillDetailVO);
				skillDetailVOList.add(skillDetailVO);
			}
		}
		
		return skillDetailVOList;
	}
	
	
}
